// pages/expData/1082/1082.js
const server = require("../server.js")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        innerHtml:[],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let inner = [];
        for (i = 1; i <= 35; i++) {
            inner.push("");
        }
        this.setData({
            innerHtml: inner,
        });
    },

    onInput: function (e) {
        let index = parseInt(e.currentTarget.id.replace("i", ""));
        let value = e.detail.value;
        let inner = this.data.innerHtml;
        inner[index] = value;
        this.setData({
            innerHtml: inner,
        });
    },

    parseData: function() {
        let ret = {v:[]};
        for (i = 0; i < this.data.innerHtml.length; i++) {
            ret.v.push(this.data.innerHtml[i]);
        }
        return ret;
    },

    formSubmit:function() {
        server.pushToServer(1041,JSON.stringify(this.parseData()));
    },
    receiveData:function(e) {
        server.fetchFromServer(1041).then(res => this.changeData(res))
    },

    changeData: function(res) {
        this.setData({
            innerHtml: res.v,
        });
    }
})